<?php
namespace App\Repos;

use App\Models\UserAddress;

class UserAddressRepo
{
	public static function  getPages($where=[],$num=10)
	{	   
		$fields = ['id','gatenum','gender','is_default','address','truename','phone','village'];
	  	$list = UserAddress::select($fields)->where($where)->paginate($num); 
	  	return $list;     
	}

	public static function destroy($where)
	{
		
		$flag = UserAddress::where($where)->delete();
		$address = UserAddress::orderBy('created_at','desc')->first();
		if($address) {
			$address->is_default = 1;
			$flag = $address->save();
		}

		return $flag;


	}

	public static function create($data)
	{
		$where['user_id'] = $data['user_id'];
		$where['shop_id'] = $data['shop_id'];
		$flag = UserAddress::where($where)->update(['is_default'=>0]);
		$data['is_default'] = 1;
		return UserAddress::create($data);
	}

	public static function find($where)
	{
		return UserAddress::where($where)->first();
	} 

	public static function update($where,$data)
	{
		return UserAddress::where($where)->update($data);
	}

	
	
	

	
	
	
}